package com.banmoon.visitor;

import com.banmoon.visitor.element.Judge;
import com.banmoon.visitor.element.Person;
import com.banmoon.visitor.element.Spectator;
import com.banmoon.visitor.visitor.Operation;

import java.util.ArrayList;
import java.util.List;

public class ObjectStructure {

    public List<Person> personElementList;

    public ObjectStructure() {
        this.personElementList = new ArrayList<>();
        this.personElementList.add(new Judge("评委A"));
        this.personElementList.add(new Judge("评委B"));
        this.personElementList.add(new Judge("评委C"));
        this.personElementList.add(new Spectator("观众甲"));
        this.personElementList.add(new Spectator("观众乙"));
    }

    public void add(Person person){
        this.personElementList.add(person);
    }

    public Person remove(Person person){
        return this.remove(person);
    }

    public void accept(Operation operation, int index){
        Person person = this.personElementList.get(index);
        if(person==null)
            throw new UnsupportedOperationException();
        person.accept(operation);
    }
}
